package com.sxpi.zixun.controller.coursecomment;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.bo.CourseCommentBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.CourseComment;
import com.sxpi.zixun.service.coursecomment.ICourseCommentService;
import com.sxpi.zixun.vo.CourseCommentVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/5 20:02
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="课程评论",tabname="kss_course_comment")
public class CourseCommentController extends BaseController {

    private final ICourseCommentService coursecommentService;

    /**
     * 查询课程评论列表信息
     * @return
     */
    @PostMapping("/coursecomment/list")
    @PugDoc(name="查询课程评论列表信息")
    public List<CourseCommentBo> findCourseCommentList() {
        return coursecommentService.findCourseCommentList();
    }

    /**
     *
     * @param coursecommentVo
     * @return
     */
    @PostMapping("/coursecomment/load")
    @PugDoc(name="查询课程评论列表信息并分页")
    public IPage<CourseCommentBo> findCourseComments(@RequestBody CourseCommentVo coursecommentVo) {
        return coursecommentService.findCourseCommentPage(coursecommentVo);
    }

    /**
     * 根据课程评论id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/coursecomment/get/{id}")
    @PugDoc(name="根据课程评论id查询明细信息")
    public CourseCommentBo getCourseCommentById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return coursecommentService.getCourseCommentById(new Long(id));
    }

    /**
     * 保存和修改课程评论
     * @param coursecomment
     * @return
     */
    @PostMapping("/coursecomment/saveupdate")
    @PugDoc(name="保存和修改课程评论")
    public CourseCommentBo saveupdateCourseComment(@RequestBody CourseComment coursecomment) {
        return coursecommentService.saveUpdateCourseComment(coursecomment);
    }

    /**
     * 根据课程评论id删除课程评论
     * @param id
     * @return
     */
    @PostMapping("/coursecomment/delete/{id}")
    @PugDoc(name="根据课程评论id删除课程评论")
    public int deleteCourseCommentById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return coursecommentService.deleteCourseCommentById(new Long(id));
    }

    /**
     * 根据课程评论ids批量删除课程评论
     * @param coursecommentVo
     * @return
     */
    @PostMapping("/coursecomment/delBatch")
    @PugDoc(name="根据课程评论ids批量删除课程评论")
    public boolean delCourseComment(@RequestBody CourseCommentVo coursecommentVo) {
        Vsserts.isEmptyEx(coursecommentVo.getBatchIds(), ResultStatusEnum.ID_NOT_EMPTY);
        return coursecommentService.delBatchCourseComment(coursecommentVo.getBatchIds());
    }
}
